package com.aabte.auth.role.domain.model;

import com.aabte.commons.ddd.shared.ValueObject;
import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Column;
import javax.persistence.Embeddable;

@SuppressWarnings("all")
@Embeddable
@Getter
@ToString
public class RoleName implements ValueObject<RoleName> {

    @Column(name = "role_name", unique = true, nullable = false)
    private String name;

    private RoleName() {
    }

    public RoleName(String name) {
        this.setName(name);
    }

    private void setName(String roleName) {
        if (StringUtils.isBlank(roleName)) {
            throw new IllegalArgumentException("roleName cannot be blank.");
        }
        this.name = StringUtils.trim(roleName);
    }

    @Override
    public boolean sameValueAs(RoleName roleName) {
        return this.name.equals(roleName.name);
    }
}
